import router from "@/router";
import store from "@/store";

const whiteList = ["/login"];
router.beforeEach((to, form, next) => {
  const token = store.getters.token;
  if (token) {
    if (!store.getters.regionId) {
      store.dispatch("user/loginApi");
    }
    if (to.path === "/login") {
      next("/");
    } else {
      next();
    }
  } else {
    if (whiteList.includes(to.path)) {
      next();
    } else {
      next("login");
    }
  }
});
